msToolJS scripting plugin for MilkShape3D

By Ulf ╓hlΘn
ulf_ohlen@hotmail.com

Overview

This plugin provides JavaScript support for MilkShape 3D 1.6.*. It wraps the MilkShape SDK in a hierarchy of JavaScript objects that can be manipulated with scripts.

The purpose of this plugin is to make it easier to add custom behaviour to MilkShape, without going through the process of writing a plugin. JavaScript is normally considered a far less complex language than C/C++. Also, no compiler is needed. However, the support for custom UIs is at the moment quite limited.

This document is only intended as a quick reference to the object model used. For info on the JavaScript language and standard objects, please refer to a JavaScript manual. See the samples for an example on how to use the plugin. I suggest reading the Report.js sample, as it makes use of the entire object hierarchy.

Installation

Copy these files to your MilkShape directory:
- msToolJS.dll The plugin
- msToolJS.htm This file
- js32.dll Mozilla's JavaScript engine (SpiderMonkey)
Samples (optional): 
- JSSamples\Report.js Creates a report of the model
- JSSamples\Spikey.js Converts each triangle into a spike
- JSSamples\Unweld.js Unwelds the vertices in the model
- JSSamples\Tetraeder.js Creates a new tetraeder mesh
- JSSamples\Octaeder.js Creates a new octaeder mesh

The plugin will also create this file when executed:
- msToolJS.ini Plugin settings


Global stuff

Global objectsTypeDescription
modelModelThe one and only Model instance. Changes to this object will show in MilkShape.
 
ConstantsTypeDescription
eSelectedintSelected flag
eSelected2intSelected flag (?)
eHiddenintHidden flag
eDirtyintDirty flag
eAveragedintAveraged flag
eUnusedint?
 
FunctionsDescription
write(message, ...)Writes one or more values to the console.
writeln(message, ...)Writes one or more values to the console. Ends with a new line.
clearConsole()Clear the console.
alert(message)Displays a messagebox
confirm(message)Displays a confirmation dialog box
showOpenDlg(dialogTitle, filter, initialDir,
defaultFile, defaultExt)
Displays a file open dialog. Returns the file path or null if cancelled.
Example: showOpenDlg("Open File", "Text|*.txt||", "C:\\Blask", "Default.txt", "txt")
showSaveDlg(dialogTitle, filter, initialDir,
defaultFile, defaultExt)
Displays a file save dialog. Returns the file path or null if cancelled.
Example: showSaveDlg("Save File", "Text|*.txt||", "C:\\Blask", "Default.txt", "txt")
prompt(message, default, title)Displays a dialog that prompts the user for a string.
gc()Runs the garbage collector

Class: Bone

PropertiesTypeDescription
flagsint
nameString
parentNameString
positionVec3
rotationVec3
positionKeysCollection of PositionKey
rotationKeysCollection of RotationKey
 
FunctionsDescription
Bone()Constructor.

Class: Collection

Collection class for storing a number of objects. Each instance is associated with a certain object type.
PropertiesTypeDescription
operator []ObjectSets/gets an item in the collection
lengthintNumber of items
 
FunctionsDescription
push(object, ...)Adds one or more items in the back of the collection. Returns a reference to the last item added.
insert(object, index)Adds an item at the specified index.
erase(first, count)Removes one or more items.
clear()Empties the collection

Class: File

Class for reading/writing files on disk.
Static open flagsTypeDescription
APPintFlag: Opens an output file for appending.
ATEintFlag: Opens an existing file and seeks the end.
INintFlag: Opens an input file.
OUTintFlag: Opens an output file.
TRUNCintFlag: Opens a file and deletes the old file, if it already exists.
BINARYintFlag: Opens a file in binary mode. Text mode is default.
curDirStringGet/set the current directory
 
PropertiesTypeDescription
pathStringFull path of the open file
nameStringName of the open file
canReadBooleanReturns true if file is open for reading
canWriteBooleanReturns true if file is open for writing
isOpenBooleangReturns true if file is open
modeintOriginal open flags
sizeintLength of the file (not implemented)
positionintRead/write position (not implemented)
eofBooleanChecks for End of file
 
FunctionsDescription
File(fileName, flags)Constructor. Optionally opens a file.
open(fileName, flags)Open a file.
close()Close the file.
read(bytes)Read a bytes long string from the file
readln()Read a line from the file
write(arg, ...)Write a number of arguments to the file
 
Static functionsDescription
exists(fileName)Returns true if specified file exists.
copy(srcName, destPath)Copy an external file
del(fileName)Delete an external file
move(srcName, destName)Move/rename an external file.
mkDir(path)Create a directory.
created(fileName)Returns creation date for a file (not implemented)
modified(fileName)Returns modified date for a file (not implemented)
attrib(fileName)Returns file attributes (not implemented)
fileSize(fileName)Returns file size (not implemented)

Class: Material

PropertiesTypeDescription
flagsint
nameString
ambientVec4
diffuseVec4
specularVec4
emissiveVec4
shininessdouble
transparencydouble
diffuseTextureString
alphaTextureString
nNameint
 
FunctionsDescription
Material(name)Constructor. Parameters are optioinal.

Class: Mesh

PropertiesTypeDescription
flagsint
nameString
materialIndexint
verticesCollection of Vertex
normalsCollection of Vec3
trianglesCollection of Triangle
 
FunctionsDescription
Mesh(name, materialIndex, flags)Constructor. Parameters are optioinal.

Class: Model

PropertiesTypeDescription
meshesCollection of Mesh
materialsCollection of Material
bonesCollection of Bone
frameint
totalFramesint
positionVec3
rotationVec3

Class: PositionKey

PropertiesTypeDescription
timedouble
positionVec3
 
FunctionsDescription
PositionKey(time, position)Constructor. Parameters are optional

Class: RotationKey

PropertiesTypeDescription
timedouble
rotationVec3
 
FunctionsDescription
RotationKey(time, rotation)Constructor. Parameters are optional

Class: Triangle

PropertiesTypeDescription
flagsint
vertexIndicesint[3]
normalIndicesint[3]
normalVec3
smoothingGroupint
 
FunctionsDescription
Triangle(vertexIndices, normalIndices, flags)Constructor. Parameters are optional

Class: Vec2

PropertiesTypeDescription
xdouble
ydouble
 
FunctionsDescription
Vec2(x, y)Constructor. Parameters are optional.

Class: Vec3

PropertiesTypeDescription
xdouble
ydouble
zdouble
 
FunctionsDescription
Vec3(x, y, z)Constructor. Parameters are optional.
length()Returns the length of a vector.
length2()Returns the squared length of a vector.
normalize(newLength)Normalize a vector. Default newLength=1.
 
Static functionsDescription
crossProd(v1, v2)Returns the cross product of two Vec3's.

Class: Vec4

PropertiesTypeDescription
xdouble
ydouble
zdouble
wdouble
 
FunctionsDescription
Vec4(x, y, z, w)Constructor. Parameters are optional.

Class: Vertex

PropertiesTypeDescription
flagsint
vertexVec3
udouble
vdouble
boneIndexint
 
FunctionsDescription
Vertex(x, y, z, u, v, boneIndex, flags)Constructor. Parameters are optional